<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>excel求相似词</title>
    <link rel="stylesheet" href="/css/bootstrap.min.css">
    <link rel="stylesheet" href="/css/style.default.css" id="theme-stylesheet">
    <script src="/js/jquery-1.9.1.min.js"></script>
    <script src="/js/bootstrap.min.js"></script>
    <script src="/js/jqpaginator.min.js"></script>
    <script src="/js/jquery-form.js"></script>
    <link rel="stylesheet" href="/css/ihg.css">
</head>
<style>
    #insertTask {
        text-align: center;
        position: absolute;
        width:400px;
        height:200px;
        left:50%;
        top:50%;
        margin-left:-200px;
        margin-top:-100px;
        border:1px solid #00F;

    }
</style>
<body>
    <div id="insertTask">
        <div class="form-group">
            <label for="similar">相似度:</label>
            <select id="similar" class="form-control" style="width: 200px" name="similar">
                <option value="">请选择</option>
                <option value="0.1">0.1</option>
                <option value="0.2">0.2</option>
                <option value="0.3">0.3</option>
                <option value="0.4">0.4</option>
                <option value="0.5">0.5</option>
                <option value="0.6">0.6</option>
                <option value="0.7">0.7</option>
                <option value="0.8">0.8</option>
                <option value="0.9">0.9</option>
                <option value="1.0">1.0</option>
            </select>
        </div>
        <div class="form-group">
            <label for="file">请上传文件</label>
            <input type="file" id="file" name="file">
        </div>
        <div>
            <button type="button" class='btn btn-primary btn-sm' id="submitbtn">执行</button>
        </div>
    </div>
    <div id="loadDiv" class="lds-css" style="visibility:hidden">
        <div class="lds-spinner">
            <div></div>
            <div></div>
            <div></div>
            <div></div>
            <div></div>
            <div></div>
            <div></div>
            <div></div>
            <div></div>
            <div></div>
        </div>
    </div>
    <script type="text/javascript" src="/js/layer.js"></script>
<script>
    /**
     * 点击添加任务弹出框的确定按钮
     * */
    $(function () {
        $("#submitbtn").click(function(){
            //展开遮罩层
            loading();

            if ($('#file')[0].files[0]==null){
                alert('请上传文件！');
                closeLoading();
                return;
            }
            if ($('#similar').val()==''||$('#similar').val()==null){
                alert('请选择相似度');
                closeLoading();
                return;
            }

            var formData = new FormData();
            formData.append('file', $('#file')[0].files[0]);
            formData.append('similar',$('#similar').val());
            $.ajax({
                url: "/upload/deal",
                type: "POST",
                data: formData,
                /**
                 *必须false才会自动加上正确的Content-Type
                 */
                contentType: false,
                /**
                 * 必须false才会避开jQuery对 formdata 的默认处理
                 * XMLHttpRequest会对 formdata 进行正确的处理
                 */
                processData: false,
                success: function (data) {
                    if (data.code=='suc'){
                        alert(data.data);
                    }else if(data.code=='900'){//处理失败
                        alert(data.msg);
                    } else if(data.code=='101'){//没有相似数据
                        alert(data.msg);
                    } else if(data.code=='404'){//文件中无数据
                        alert(data.msg);
                    } else if(data.code=='400'){//文件上传格式有误
                        alert(data.msg);
                    } else if(data.code=='500'){
                        alert(data.msg);
                    }else if(data.code=='fail') {
                        alert(data.msg);
                    }else {
                        alert('hi，未知错误，请联系技术部！');
                    }
                    //遮罩层关闭
                    closeLoading();

                },
                error: function (data) {
                    alert(data.msg);
                    //遮罩层关闭
                    closeLoading();
                }
            });
        })
    });
    /**
     * 遮罩层js
     */
    function loading() {
        document.getElementById("loadDiv").style.visibility = "visible"; //显示
    }
    function closeLoading() {
        document.getElementById("loadDiv").style.visibility = "hidden"; //隐藏
    }

</script>
</body>
</html>